package br.ucdb.android.maps;



import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.Toast;
import br.ucdb.acad.domain.GpsPosition;
import br.ucdb.acad.util.GpsUtil;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;


public class GasMapsActivity extends MapActivity {
    /** Called when the activity is first created. */
	MapController mc;
	GeoPoint p;
	MapView mv;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        StartScreen ss = new StartScreen();
        ss.onCreate(savedInstanceState);
        
        MapView mapview = (MapView) findViewById (R.id.mapview);
        mapview.setBuiltInZoomControls (true);
        
        
        MapView mapView = (MapView) findViewById(R.id.mapview) ;
        mapView.setClickable(true);
        
        MyLocationOverlay mlo = new MyLocationOverlay(this, mapView) ;
        mlo.enableCompass() ;
        mlo.enableMyLocation() ;
        mapView.getOverlays().add(mlo) ;
        
        mc = mapView.getController();
        String coordinates[] = {"-20.464008", "-54.61338"};
        double lat = Double.parseDouble(coordinates[0]);
        double lng = Double.parseDouble(coordinates[1]);
 
        p = new GeoPoint(
            (int) (lat * 1E6), 
            (int) (lng * 1E6));
 
        mc.animateTo(p);
        mc.setZoom(17);
        
      //---Add a location marker---
        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = mapView.getOverlays();
        listOfOverlays.clear();
        listOfOverlays.add(mapOverlay);        
 
        mapView.invalidate();
    }
    
    @ Override
    protected boolean isRouteDisplayed () {
        return false;
    }
    
    class MapOverlay extends com.google.android.maps.Overlay
    {
        @Override
        public boolean draw(Canvas canvas, MapView mapView, 
        boolean shadow, long when) 
        {
            super.draw(canvas, mapView, shadow);                   
 
            //---translate the GeoPoint to screen pixels---
            Point screenPts = new Point();
            mapView.getProjection().toPixels(p, screenPts);
 
            //---add the marker---
            Bitmap bmp = BitmapFactory.decodeResource(
                getResources(), R.drawable.images);            
            canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);         
            return true;
        }
     
 
        @Override
        public boolean onTouchEvent(MotionEvent event, MapView mapView) 
        {   

            
            return false;
        }
        
    }
        
}
